package com.zhang.web.servlet;


import com.zhang.pojo.ResultInfo;
import com.zhang.pojo.User;
import com.zhang.service.UserService;
import com.zhang.service.impl.UserServiceImpl;
import com.zhang.utils.JsonUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getUserNameServlet")
public class GetUserNameServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultInfo info = new ResultInfo();

        User user =(User) req.getSession().getAttribute("user");
        if(user != null){
            info.setFlag(true);
            info.setData(user.getUsername());
        }else{
            info.setFlag(true);
            info.setData(" ");
        }


        JsonUtils.send(resp,info);

    }


}


